package grammaire.calcotactile;

import grammaire.calcotactile.MainActivity.Etat;

public class Expression {
	
	public enum OPERANDE {
		Plus, Moins, Div, Mult
	}
	
	protected int nb1, nb2;
	protected OPERANDE op;
	
	public Expression() {
		this.nb1 = 0;
		this.nb2 = 0;
		this.op = null;
	}
	
	public Expression(int i, int j) {
		this.nb1 = i;
		this.nb2 = j;
		this.op = null;
	}
	
	public Expression(int i, int j, OPERANDE op) {
		this.nb1 = i;
		this.nb2 = j;
		this.op = op;
	}
	
	public int getNb1() {
		return nb1;
	}

	public void setNb1(int nb1) {
		this.nb1 = nb1;
	}

	public int getNb2() {
		return nb2;
	}

	public void setNb2(int nb2) {
		this.nb2 = nb2;
	}

	public OPERANDE getOp() {
		return op;
	}

	public void setOp(OPERANDE op) {
		this.op = op;
	}

	public int calcul(Etat etat) {
		if(etat != Etat.Egal)
			return 0;
		switch(op) {
		case Plus: return Plus();
		case Moins: return Moins();
		case Mult: return Mult();
		case Div: return Div();
		default : break;
		}
		return 0;
	}

	private int Plus() { return nb1 + nb2; }
	private int Moins() { return nb1 - nb2; }
	private int Div() { 
		if(nb2 != 0) 
			return nb1 / nb2; 
	return 0;
	}
	private int Mult() { return nb1 * nb2; }
}
